home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Divers / DinkClass ƒ / DC TextEdit / TEditMainProgram.c < prev   
Encoding:
C/C++ Source or Header  |  1992-10-16  |  3.6 KB  |  177 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        TEditMainProgram.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    © 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10. //
  11. // this is the model main function modual for the typical DinkClass
  12. // application
  13. //
  14.  
  15. #include "DTEditApp.h"
  16. #include "DTEditDoc.h"
  17. #include "DinkUtils.h"
  18.  
  19. //
  20. //Core apple event prototypes
  21. //
  22.  
  23. void DoAEInstallation(void);
  24.  
  25. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply,
  26.                          long myRefCon);
  27. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, 
  28.                          long myRefCon);
  29. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  30.                          long myRefCon);
  31. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  32.                          long myRefCon);
  33.  
  34.  
  35. main()
  36. {
  37.     DApplication    *theApp;
  38.     
  39.     InitToolBox(5);
  40.  
  41.     if(!System7Available() )
  42.         DebugStr( "\p No System 7!!" );
  43.  
  44.     DEventHandler::gApplication = NULL;// to make sure no messages get sent to gApplication 
  45.                                     // before it is instanicated.  otherwise the Application
  46.                                     // object will be sending install handler message to itself
  47.                                     // befor it is fully instaniated.
  48.     
  49.     theApp = new DTEditApp;
  50.     
  51.     DEventHandler::gApplication = theApp;
  52.     DEventHandler::gPassItOn = TRUE;
  53.  
  54.     theApp->fCreator = 'MkGr';
  55.     theApp->fClipType = 'TEXT';
  56.     theApp->fMainFileType = 'TEXT';
  57.  
  58.     DoAEInstallation();// the AE-handler procs refrence gApplication 
  59.                         // so I'm initializing the AEvents after I have
  60.                         // a valid gApplication
  61.     
  62.     
  63.     if(theApp->InitApp() )
  64.     {            
  65.         theApp->MakeDDoc(FALSE);
  66.         do
  67.         {
  68.             theApp->EventLoop();
  69.         } while(!theApp->CleanUp());
  70.     }
  71.     delete theApp;
  72.     ExitToShell();    //last good bye kiss
  73. }// the end
  74.  
  75.  
  76.  
  77.  
  78. void DoAEInstallation(void)
  79. {
  80.  
  81.     AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,
  82.                             (EventHandlerProcPtr)HandleODOC, 0, false);
  83.  
  84.     AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,
  85.                             (EventHandlerProcPtr)HandleQUIT, 0, false);
  86.  
  87.     AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments,
  88.                             (EventHandlerProcPtr)HandlePDOC, 0, false);
  89.  
  90.     AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,
  91.                             (EventHandlerProcPtr)HandleOAPP, 0, false);
  92.  
  93. }                            
  94.  
  95.  
  96.  
  97. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  98. {
  99.     OSErr myErr;
  100.     
  101.     myErr = RequiredCheck( theAppleEvent);
  102.     if (myErr) 
  103.         return myErr;
  104.     
  105.     DEventHandler::gApplication->fDone = true;
  106.     return noErr;
  107. }
  108.  
  109.  
  110.  
  111. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  112. {
  113.     OSErr myErr;
  114.  
  115.     myErr = RequiredCheck( theAppleEvent);
  116.     if (myErr) 
  117.         return myErr;
  118.     
  119.     return noErr;
  120. }
  121.  
  122.  
  123.  
  124. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  125. {
  126.     OSErr myErr;
  127.  
  128.     myErr = RequiredCheck( theAppleEvent);
  129.     if (myErr) 
  130.         return myErr;
  131.     
  132.     return errAEEventNotHandled;
  133. }
  134.  
  135.  
  136. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  137. {
  138.     OSErr myErr;
  139.     AEDescList  docList;
  140.     FSSpec        myFSS;
  141.     long        i;
  142.     long        itemsInList;
  143.     AEKeyword    theKeyWord;
  144.     DescType    typeCode;
  145.     Size        actualSize;
  146.     WindowPtr    docWindow;
  147.     DDocument* newDoc;
  148.  
  149.     myErr = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
  150.     if ( myErr)
  151.         return(myErr);
  152.  
  153.     myErr = RequiredCheck( theAppleEvent);
  154.     if (myErr) 
  155.         return myErr;
  156.  
  157.  
  158.     myErr = AECountItems(&docList, &itemsInList);
  159.     if (myErr) 
  160.         return myErr;
  161.         
  162.     for (i = 1; ((i <= itemsInList) && (!myErr)); ++i) 
  163.     {
  164.         myErr = AEGetNthPtr( &docList, i, typeFSS, &theKeyWord,    &typeCode, 
  165.             (Ptr)&myFSS, sizeof(FSSpec), &actualSize );
  166.         
  167.         if (myErr) 
  168.             return myErr;
  169.         
  170.         newDoc = new DTEditDoc;
  171.         if (newDoc)
  172.             newDoc->AEInitDoc(&myFSS); 
  173.     }
  174.     return noErr;
  175. }
  176.  
  177.